Added a check on the colormap depth to gdk_drawable_set_colormap()
authorRon Steinke <rsteinke@src.gnome.org>
Mon, 23 Jul 2001 21:28:38 +0000 (21:28 +0000)
committerRon Steinke <rsteinke@src.gnome.org>
Mon, 23 Jul 2001 21:28:38 +0000 (21:28 +0000)
        * gdk/gdkdraw.c: Added a check on the colormap depth to
        gdk_drawable_set_colormap()
        * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
        patch to fix colorsel and my patch to fix gdk_drawable_get_image()
        for pixmaps without visuals (more specifically, bitmaps)
        * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
        doesn't set a colormap with the wrong depth

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gdk/gdkdraw.c
gdk/x11/gdkimage-x11.c
gdk/x11/gdkpixmap-x11.c

index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index ba38cf2a9f0ed918e54b3d72094af1206668e95c..cedb7ab8db58eeaf87d56ddc39388db292c2f8db 100644 (file)
@@ -1,3 +1,14 @@
+2001-07-23  Ron Steinke  <rsteinke@w-link.net>
+
+       * gdk/gdkdraw.c: Added a check on the colormap depth to
+       gdk_drawable_set_colormap()
+       * gdk/x11/gdkimage-x11.c: combination of Mathias Hasselmann's
+       patch to fix colorsel and my patch to fix gdk_drawable_get_image()
+       for pixmaps without visuals (more specifically, bitmaps)
+       * gdk/x11/gdkpixmap-x11.c: Fixed gdk_pixmap_new() so it
+       doesn't set a colormap with the wrong depth
+
+
 2001-07-22  Anders Carlsson  <andersca@gnome.org>
 
        * gtk/gtktreeview.c (gtk_tree_view_class_init): Replace the
index d05bb1b7f4180e0f0300b2a3179837e9917beb97..b4de48a2f56f293a9a7190c6558a9bdbb80d2b41 100644 (file)
@@ -198,6 +198,8 @@ gdk_drawable_set_colormap (GdkDrawable *drawable,
                            GdkColormap *cmap)
 {
   g_return_if_fail (GDK_IS_DRAWABLE (drawable));
+  g_return_if_fail (cmap == NULL || gdk_drawable_get_depth (drawable)
+                    == cmap->visual->depth);
 
   GDK_DRAWABLE_GET_CLASS (drawable)->set_colormap (drawable, cmap);
 }
index ac78afd50712ca318fb580cc91d4f56727585844..b473fac67528e11f983e07c5533498f34d44f16c 100644 (file)
@@ -382,6 +382,7 @@ _gdk_x11_get_image (GdkDrawable    *drawable,
   GdkDrawableImplX11 *impl;
   GdkVisual *visual;
   gboolean have_grab;
+  GdkRectangle req;
   GdkRectangle window_rect;
   XImage *ximage;
   
@@ -389,32 +390,29 @@ _gdk_x11_get_image (GdkDrawable    *drawable,
 
   visual = gdk_drawable_get_visual (drawable);
 
-  if (visual == NULL)
-    {
-      g_warning ("To get the image from a drawable, the drawable "
-                 "must have a visual and colormap; calling "
-                 "gtk_drawable_set_colormap() on a drawable "
-                 "created without a colormap should solve this problem");
+  g_assert (visual || !GDK_IS_WINDOW (drawable));
 
-      return NULL;
-    }
-  
   impl = GDK_DRAWABLE_IMPL_X11 (drawable);
   
   have_grab = FALSE;
-  window_rect.x = x;
-  window_rect.y = y;
-  window_rect.width = width;
-  window_rect.height = height;
+
   if (GDK_IS_WINDOW (drawable))
     {
       GdkRectangle screen_rect;
+      Window child;
+
+      g_assert (visual);
       
       have_grab = TRUE;
       gdk_x11_grab_server ();
+      
+      XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (drawable),
+                            gdk_root_window,
+                            GDK_DRAWABLE_XID (drawable),
+                            0, 0, 
+                            &screen_rect.x, &screen_rect.y, 
+                            &child);
 
-      screen_rect.x = 0;
-      screen_rect.y = 0;
       screen_rect.width = gdk_screen_width ();
       screen_rect.height = gdk_screen_height ();
       
@@ -428,42 +426,109 @@ _gdk_x11_get_image (GdkDrawable    *drawable,
                                NULL);
 
       if (gdk_error_trap_pop () ||
-          !gdk_rectangle_intersect (&window_rect, &screen_rect,
+          !gdk_rectangle_intersect (&window_rect, &screen_rect, 
                                     &window_rect))
         {
           gdk_x11_ungrab_server ();
-          return NULL;
+          return image = gdk_image_new (GDK_IMAGE_FASTEST,
+                                        visual,
+                                        width, height);
         }
     }
+  else
+    {
+      window_rect.x = 0;
+      window_rect.y = 0;
+      gdk_drawable_get_size (drawable,
+                            &window_rect.width,
+                            &window_rect.height);
+    }
+      
+  req.x = x;
+  req.y = y;
+  req.width = width;
+  req.height = height;
+  
+  /* window_rect specifies the part of drawable which we can get from
+     the server in window coordinates. 
+     For pixmaps this is all of the pixmap, for windows it is just 
+     the onscreen part. */
+  if (!gdk_rectangle_intersect (&req, &window_rect, &req) && visual) 
+    {
+      if (have_grab)
+       gdk_x11_ungrab_server ();
+      return image = gdk_image_new (GDK_IMAGE_FASTEST,
+                                    visual,
+                                    width, height);
+    }
 
-  image = gdk_image_new (GDK_IMAGE_FASTEST,
-                         visual,
-                         width, height);
+  if (req.x != x || req.y != y)
+    {
+      g_assert (GDK_IS_WINDOW (drawable));
+      g_assert (visual);
 
-  if (image == NULL)
-    return NULL;
+      image = gdk_image_new (GDK_IMAGE_FASTEST,
+                             visual,
+                             width, height);
+      if (image == NULL)
+        return NULL;
 
-  private = PRIVATE_DATA (image);
-  
-  gdk_error_trap_push ();
+      private = PRIVATE_DATA (image);
 
-  ximage = XGetSubImage (impl->xdisplay,
-                         impl->xid,
-                         x, y, width, height,
-                         AllPlanes, ZPixmap,
-                         private->ximage,
-                         x, y);
+      gdk_error_trap_push ();
 
-  if (have_grab)
-    gdk_x11_ungrab_server ();
-  
-  if (gdk_error_trap_pop () || ximage == NULL)
-    {
-      g_object_unref (G_OBJECT (image));
-      return NULL;
+      ximage = XGetSubImage (impl->xdisplay,
+                             impl->xid,
+                             req.x, req.y, req.width, req.height,
+                             AllPlanes, ZPixmap,
+                             private->ximage,
+                             req.x - x, req.y - y);
+
+      if (have_grab)
+        gdk_x11_ungrab_server ();
+      
+      if (gdk_error_trap_pop () || ximage == NULL)
+        {
+          g_object_unref (G_OBJECT (image));
+          return NULL;
+        }
+
+      g_assert (ximage == private->ximage);
     }
+  else
+    {
+
+      ximage = XGetImage (impl->xdisplay,
+                          impl->xid,
+                          x, y, width, height,
+                          AllPlanes, ZPixmap);
+
+      if (!ximage)
+        {
+          if (have_grab)
+            gdk_x11_ungrab_server ();
+          return NULL;
+        }
 
-  g_assert (ximage == private->ximage);
+      image = g_object_new (gdk_image_get_type (), NULL);
+
+      private = PRIVATE_DATA (image);
+
+      private->xdisplay = gdk_display;
+      private->ximage = ximage;
+
+      image->type = GDK_IMAGE_NORMAL;
+      image->visual = visual; /* May be NULL */
+      image->width = width;
+      image->height = height;
+      image->depth = gdk_drawable_get_depth (drawable);
+
+      image->mem = private->ximage->data;
+      image->bpl = private->ximage->bytes_per_line;
+      image->bits_per_pixel = private->ximage->bits_per_pixel;
+      image->bpp = (private->ximage->bits_per_pixel + 7) / 8;
+      image->byte_order = private->ximage->byte_order; 
+    }
 
   return image;
 }
index 03ef5888cf865162a8a2aea006b97872440fedc7..fe0b421a0c9910dbcc7a9d3f31255ab2eadcd560 100644 (file)
@@ -150,6 +150,7 @@ gdk_pixmap_new (GdkWindow *window,
   GdkDrawableImplX11 *draw_impl;
   GdkPixmapImplX11 *pix_impl;
   GdkColormap *cmap;
+  gint window_depth;
   
   g_return_val_if_fail (window == NULL || GDK_IS_WINDOW (window), NULL);
   g_return_val_if_fail ((window != NULL) || (depth != -1), NULL);
@@ -161,8 +162,9 @@ gdk_pixmap_new (GdkWindow *window,
   if (GDK_WINDOW_DESTROYED (window))
     return NULL;
 
+  window_depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
   if (depth == -1)
-    depth = gdk_drawable_get_depth (GDK_DRAWABLE (window));
+    depth = window_depth;
 
   pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
   draw_impl = GDK_DRAWABLE_IMPL_X11 (GDK_PIXMAP_OBJECT (pixmap)->impl);
@@ -179,7 +181,7 @@ gdk_pixmap_new (GdkWindow *window,
   pix_impl->height = height;
   GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
 
-  if (window)
+  if (depth == window_depth)
     {
       cmap = gdk_drawable_get_colormap (window);
       if (cmap)